/*
 * RentStrutsAction.java
 *
 * Created on April 26, 2007, 12:13 PM
 */

package com.abbh.libcommunity.struts.actions;

import com.abbh.libcommunity.bo.impl.ItemBOImpl;
import com.abbh.libcommunity.bo.impl.ItemRentBOImpl;
import com.abbh.libcommunity.bo.impl.UserBOImpl;
import com.abbh.libcommunity.dao.impl.ItemRentDAOImpl;
import com.abbh.libcommunity.model.Item;
import com.abbh.libcommunity.model.User;
import com.abbh.libcommunity.struts.beans.RentStrutsActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
/**
 *
 * @author Abdul Khader J Syed
 * @version
 */

public class RentStrutsAction extends Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    private final static String USERNOTFOUND="usernotfound";
     private final static String ITEMNOTFOUND="itemnotfound";
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
               
        RentStrutsActionForm a=(RentStrutsActionForm)form;


         
        UserBOImpl u=new UserBOImpl();
        
        User user=u.findByUserId(a.getUserId());
        
        if(user==null)
        {
            return mapping.findForward(USERNOTFOUND);
        }
        
        ItemBOImpl i=new ItemBOImpl();
        Item item=i.findByItemId(a.getItemId());
        
        if(item==null)
        {
               return mapping.findForward(ITEMNOTFOUND);
        }
        
       ItemRentBOImpl itemrent=new ItemRentBOImpl();
       
       itemrent.rentItem(user,item);
         
                    
        return mapping.findForward(SUCCESS);
        
    }
}
